#include <iostream>
#include <fstream>
#include <string>

using namespace std;

bool num_str(char str)
{
    if((str>='A'&&str<'z')||(str>='0'&&str<='9'))
        return true;
    else 
        return false;
}

void count(fstream &outflie,int *cnt)
{
    char str[256];
    while(outflie.getline(str,256))
    {
        int tmp=0;

        for(int i=0;i<strlen(str);i++)
        {
            if(str[i]==' '||str[i]=='.'||str[i]=='?'||str[i]=='!')
                cnt[1]++;tmp++;

            if(num_str(str[i]))
            {
                cnt[0]++;
                tmp++;
            }
        }

        if(tmp!=0) cnt[2]++;
        tmp=0;
    }
}

int main()
{
    char filename[256];
    int cnt[3]={0};

    cout<<"enter the filename"<<endl;
    cin.getline(filename,256);

    fstream outfile(filename,ios_base::out|ios_base::binary);

    count(outfile,cnt);

    cout<<"characters;"<<cnt[0]<<endl;
    cout<<"words:"<<cnt[1]<<endl;
    cout<<"lines:"<<cnt[2]<<endl;

    outfile.close();

    system("pause");
    return 0;
}



